<?php

// [ 获取分页数据 ]

namespace app\api\lib;
use think\Db;

class Page
{
    // 分页数据
    private static $_pagelist = [
        'page' => 1,
        'show' => 10,
        'prev' => 0,
        'next' => 0,
        'list' => [],
    ];

    // 计算分页返回
    public static function run($table, $page, $show, $where, $list)
    {
        self::$_pagelist['page'] = $page;
        self::$_pagelist['prev'] = $page - 1;
        self::$_pagelist['next'] = $page + 1;
        self::$_pagelist['list'] = $list;
        $ret = Db::name($table)->where($where)->page(self::$_pagelist['next'],$show)->limit(1)->select();
        empty($ret) && self::$_pagelist['next'] = 0;
        return self::$_pagelist;
    }
}
